﻿$("#DecorationCompanyID").change(function () { GetStore() });//加载门店
$("#IntermediaryID").change(function () { GetConsultant() });//加载装修顾问
function GetStore() {
    $.getJSON(
    "/DecorationRunnings/BlocokLoad",
    { companyid: $("#DecorationCompanyID").val() },
    function (data) {
        if (data.type == 1) {
            $("#IntermediaryID").empty();//清空城市SELECT控件
            data = data.data;
            $("#IntermediaryID").append(' <option value="0">全部</option>');
            for (var i = 0; i < data.decorationCompanyStore.length; i++) {
                $("#IntermediaryID").append(' <option value="' + data.decorationCompanyStore[i].id + '">' + data.decorationCompanyStore[i].text + '</option>');
            }
            GetConsultant();
        }
    });
}
function GetConsultant() {
    $.getJSON(
        "/DecorationRunnings/BlocokLoad",
        {
            storeid: $("#IntermediaryID").val()
        },
        function (data) {
            if (data.type == 1) {
                $("#DecorationConsultantName").empty();//清空区县SELECT控件
                data = data.data;
                $("#DecorationConsultantName").append(' <option value="0">全部</option>');
                for (var i = 0; i < data.decorationConsultant.length; i++) {
                    $("#DecorationConsultantName").append(' <option value="' + data.decorationConsultant[i].id + '">' + data.decorationConsultant[i].text + '</option>');
                }
            }
        });
}

//加载基本数据
$.ajax({
    url: "/DecorationRunnings/DictionaryLoad", type: "post", async: false, success: function (data) {
        if (data.type == 1) {
            data = data.data;
            //装修公司
            $("#DecorationCompanyID").empty();
            $("#DecorationCompanyID").append(' <option value="0">全部</option>');
            for (var i = 0; i < data.decorationCompany.length; i++) {
                $("#DecorationCompanyID").append(' <option value="' + data.decorationCompany[i].id + '">' + data.decorationCompany[i].text + '</option>');
            }
            //门店
            $("#IntermediaryID").empty();
            $("#IntermediaryID").append(' <option value="0">全部</option>');
            for (var i = 0; i < data.decorationCompanyStore.length; i++) {
                $("#IntermediaryID").append(' <option value="' + data.decorationCompanyStore[i].id + '">' + data.decorationCompanyStore[i].text + '</option>');
            }
            //装修顾问
            $("#DecorationConsultantName").empty();
            $("#DecorationConsultantName").append(' <option value="0">全部</option>');
            for (var i = 0; i < data.decorationConsultant.length; i++) {
                $("#DecorationConsultantName").append(' <option value="' + data.decorationConsultant[i].id + '">' + data.decorationConsultant[i].text + '</option>');
            }
            //渠道人员
            $("#OriginStaffID").empty();
            $("#OriginStaffID").append(' <option value="0">全部</option>');
            for (var i = 0; i < data.staff.length; i++) {
                $("#OriginStaffID").append(' <option value="' + data.staff[i].id + '">' + data.staff[i].text + '</option>');
            }
        }
    }
});


$(".down").click(function (event) {
    $('.dropdown-menu').hide();
    $(this).parent().find('.dropdown-menu').show();
    event.stopPropagation();
    $(document).click(function () {
        $(".dropdown-menu").hide();
    });
    $(".dropdown-menu a").click(function () {
        $(this).parent().parent().hide();
    });
});
function selectDate(day) {
    var mydate = new Date();
    var endDate = "" + mydate.getFullYear() + "-";
    endDate += (mydate.getMonth() + 1) + "-";
    endDate += mydate.getDate();
    $("#endDate").val(endDate);

    if (day == -1) {
        mydate.setYear(mydate.getFullYear() - 20);
    } else {
        mydate.setDate(mydate.getDate() - day);
    }


    var beginDate = "" + mydate.getFullYear() + "-";
    beginDate += (mydate.getMonth() + 1) + "-";
    beginDate += mydate.getDate();
    $("#beginDate").val(beginDate);
}


function QuickBtn(obj) {
    var val = 0;
    if (obj.type == "button") {
        val = $(obj).attr("tradeName");
    } else {
        val = $(obj).parent().parent().prev().prev().attr("tradeName");
    }
    selectDate($(obj).attr("value"));
    $("#tradeType").val(val);

}